package com.minimalist.lindi.mapper;

import com.mybatisflex.core.BaseMapper;
import com.minimalist.common.entity.lindi.po.LindiPurchaseApplicationFile;
import com.mybatisflex.core.query.QueryWrapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

import static com.minimalist.common.entity.lindi.po.table.LindiPurchaseApplicationFileTableDef.LINDI_PURCHASE_APPLICATION_FILE;

/**
 * 林地指标交易平台_购买申请文件 映射层。
 *
 * @author 11987
 * @since 2025-07-01
 */
public interface LindiPurchaseApplicationFileMapper extends BaseMapper<LindiPurchaseApplicationFile> {

    /**
     * 根据购买申请ID和文件类型查询文件列表
     *
     * @param purchaseApplicationId 购买申请ID
     * @param fileType 文件类型
     * @return 文件列表
     */
    @Select("SELECT * FROM LINDI_PURCHASE_APPLICATION_FILE WHERE PURCHASE_APPLICATION_ID = #{purchaseApplicationId} AND FILE_TYPE = #{fileType}")
    List<LindiPurchaseApplicationFile> selectFileListByPurchaseApplicationIdAndFileType(
            @Param("purchaseApplicationId") Long purchaseApplicationId,
            @Param("fileType") String fileType);

    /**
     * 根据购买申请ID查询文件列表
     *
     * @param purchaseApplicationId 购买申请ID
     * @return 文件列表
     */
    default List<LindiPurchaseApplicationFile> selectFileListByPurchaseApplicationId(Long purchaseApplicationId) {
        return selectListByQuery(QueryWrapper.create()
                .eq(LindiPurchaseApplicationFile::getPurchaseApplicationId, purchaseApplicationId));
    }

    /**
     * 根据购买申请ID删除文件
     *
     * @param purchaseApplicationId 购买申请ID
     * @return 删除数量
     */
    default int deleteFilesByPurchaseApplicationId(Long purchaseApplicationId) {
        return deleteByQuery(QueryWrapper.create()
                .eq(LindiPurchaseApplicationFile::getPurchaseApplicationId, purchaseApplicationId));
    }

    /**
     * 根据文件ID查询文件
     *
     * @param fileId 文件ID
     * @return 文件信息
     */
    default LindiPurchaseApplicationFile selectFileByFileId(Long fileId) {
        return selectOneByQuery(QueryWrapper.create()
                .eq(LindiPurchaseApplicationFile::getFileId, fileId));
    }

    /**
     * 根据文件ID删除文件
     *
     * @param fileId 文件ID
     * @return 删除数量
     */
    default int deleteFileByFileId(Long fileId) {
        return deleteByQuery(QueryWrapper.create()
                .eq(LindiPurchaseApplicationFile::getFileId, fileId));
    }

}
